package com.alexsun.navcard.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.alexsun.navcard.R
import com.alexsun.navcard.databinding.FragmentHomeBinding
import com.alexsun.navcard.entities.ShopItem


class HomeFragment : Fragment() {

    private var _binding: FragmentHomeBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        _binding = FragmentHomeBinding.inflate(inflater, container, false)

        val spinner: Spinner = binding.spinnerType
        this.context?.let {
            ArrayAdapter.createFromResource(
                it, R.array.foot_types, android.R.layout.simple_spinner_item
            ).also { adapter ->
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
                spinner.adapter = adapter
            }
        }
        val filterSpinner: Spinner = binding.spinnerFilter
        this.context?.let {
            ArrayAdapter.createFromResource(
                it, R.array.foot_filter, android.R.layout.simple_spinner_item
            ).also { adapter ->
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
                filterSpinner.adapter = adapter
            }
        }

        val shopArray = arrayOf(
            ShopItem("鸡你太美炸鸡店", "你干嘛哎呦~"),
            ShopItem("ikun 特色餐厅", "蒸梅油酥汁"),
            ShopItem("开团炸鸡店", "香翅捞饭"),
            ShopItem("rap 篮球店", "香精煎鱼"),
            ShopItem("铁山靠炸鸡店", "荔枝"),
            ShopItem("哦~baby", "人参公鸡"),
            ShopItem("只因炸坤店", "蒸乌鱼"),
            ShopItem("蠢蠢欲动", "蒸梅油酥芝"),
            ShopItem("让我怎么去否认", "蒸虾头"),
            ShopItem("Ctrl", "香菜凤仁鸡"),
            ShopItem("篮球和鸡", "梅油焦羊"),
        )
        val shopAdapter = ShopAdapter(shopArray, this.context)
        val recyclerView = binding.shopView
        recyclerView.adapter = shopAdapter
        val layoutManager = LinearLayoutManager(this.context)
        recyclerView.layoutManager = layoutManager
        return binding.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}